clear all 
set more off 
set maxvar 15000 
clear matrix


	use "$Mydirectory1/3_Output/2_PooledData_analysis.dta", clear 
    keep if baseline_sample==1
    
    gen level = exp(log_father_baseline)
    gen squared = (level*level) /100        
    
* Linear and quadratic regressions; evaluate at 25th percentile of parental income distribution 
    
    levelsof decade, local(decades)
        foreach d of local decades {
        eststo clear
        
            di "`d'"
            
            sum level if decade==`d' [aw=wgt_sex_race], d
            local numb1 = `r(p25)'
            
            reg fam_inc_real level squared  [aw=wgt_sex_race] if decade==`d', robust 
            estimates store log`d'
                        
            local number1 = _b[level]+(2*(_b[squared]/100)*`numb1')
            estadd scalar eval = `number1' 
            
        
        }
        
    label var level "Level coefficient, linear"
    label var squared "Level coeff., quadratic ($\times$100)"
  
    #delimit ; 
    esttab log1910 log1920 log1930 log1940 log1950 log1960 log1970 using "$Mydirectory2/appendix_d/table_main_estimates_levels_quadratic.tex", replace     booktabs nostar label  keep(level squared) nobase noomit nonote alignment(c c) width(\hsize) se(3) b(3) brackets
    mtitles("1910" "1920" "1930" "1940" "1950" "1960" "1970") 
    stats(eval N, fmt(%04.3fc %9.2gc) label("Derivative at 25th percentile" "Observations"));
    #delimit cr

